package org.grow.auth.service;

import org.grow.auth.dao.UserInfoRepository;
import org.grow.auth.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * @Author: xwg
 * @CreateDate: 2021/10/14
 */

@Service
public class AnonymousProvider {
    public static final String anonymousUser="anonymous";
    @Autowired
    private UserInfoService userInfoService;
    public UserDetails provide(){
        try{
            UserDetails userDetails = userInfoService.loadUserByUsername(anonymousUser);

            return userDetails;

        }catch(Exception e){
            UserInfo userInfo = new UserInfo();
            userInfo.setIsEnable(true);
            userInfo.setUsername(anonymousUser);
            userInfo.setUserId(-1);
            userInfo.setPassword("00000");

            return userInfo;
        }


    }
}
